<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>test1</title>
</head>

<body>
    <iframe src="http://localhost:8081/html_review_code/test2.html" frameborder="1"></iframe>
    <script>
        var ifr = document.querySelector('iframe')
        // ifr.style.display = 'none'
        var flag = 0;
        ifr.onload = function () {
            if (flag == 1) {
                console.log('跨域获取数据', ifr.contentWindow.name);
                ifr.contentWindow.close();
            } else if (flag == 0) {
                flag = 1;
                ifr.contentWindow.location = 'http://localhost:8080/html_review_code/line.html'; // 只需设置同源即可
            }
        }
    </script>
</body>

</html>